package org.example2;

import java.io.OutputStream;
import java.net.Socket;
import java.util.concurrent.TimeUnit;

public class SingleStringClient {
    public static void main(String[] args) throws Exception {

        Socket socket = new Socket("localhost", 8888);

        OutputStream outputStream = socket.getOutputStream();

        for (int i = 1; i <=2; i++) {
            byte[] bytes = "abc1\n".getBytes();

            outputStream.write(bytes);
            outputStream.flush();
        }



        TimeUnit.SECONDS.sleep(8);

//  注意 socket.close()方法,具有 socket.shutdownOutput();的功能,通知对方,我已经写完了
        socket.close();
        System.out.println("socket的close方法执行了---------毫秒值:"+System.currentTimeMillis());

//        socket.shutdownOutput();
//        System.out.println("socket的shutdownOutput方法执行了");

        byte b1= -1;
        byte[] bytes2={ b1};
        outputStream.write(bytes2);
        outputStream.flush();

        System.out.println("-----------死循环之前-------------");

        while (true) {

        }

    }
}
